/**
 * Created by yujianfu on 2016/11/10.
 */
import * as React from 'react'
import {Popover, Card, Table, Icon, Collapse, Button, message} from 'antd'
import {fetchPost} from '../../../../utils/request'
import styles from '../../../finance/photoCheck/common/detail/Index.less'
import Styles from '../../../finance/common/detail/Index.less'
import PhotoStyle from '../../less/Photo.less'
import Viewer from 'react-viewer'
import 'react-viewer/dist/index.css'

const Panel = Collapse.Panel

class TradeBankInfo extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      userId: props.userId,
      tradeNo: props.tradeNo,
      activeIndex: 0,
      bankInfo: null,
    }
  }

  componentWillReceiveProps(props) {
    if (this.state.userId != props.userId || this.state.tradeNo != props.tradeNo) {
      this.setState({
        userId: props.userId,
        tradeNo: props.tradeNo
      }, () => {
        this.getData()
      })
    }
  }

  componentDidMount() {
    if (this.state.userId && this.state.tradeNo) {
      this.getData()
    }
  }

  getData() {
    if (this.state.tradeNo != null) {
      fetchPost(`/user/${this.state.tradeNo}/trade/bank/info`, {}).then(res => {
        if (res.code === 0) {
          this.setState({
              bankInfo: res.data,
            }
          );
        }
      })
    } else {
      this.setState({
        bankInfo: null,
      })
    }
  }

  render() {
    if (this.state.bankInfo == null) {
      return (
        <Card title="Bank Info" bodyStyle={{padding: 0, maxHeight: 210, overflow: 'auto'}} noHovering={true}>
          <span className="no-data"><Icon type='frown-o'/>No data</span>
        </Card>
      )
    }
    let images = []
    let slf = this

    return (
      <div className={styles.detailModule}>
        <Card title="Bank Info" bodyStyle={{padding: 0, maxHeight: 210, overflow: 'auto'}} noHovering={true}>
          <div className={Styles.oneLineContent}>
            <span style={{width: '20%'}}>Bank Name</span>
            :
            <span style={{width: '80%', paddingLeft: 5}}>
                {this.state.bankInfo == null ? <span
                    style={{color: '#4876FF'}}>querying...</span> : this.state.bankInfo.bankName}
              </span>
          </div>
          <div className={Styles.oneLineContent}>
            <span style={{width: '20%'}}>Bank No</span>
            :
            <span style={{width: '80%', paddingLeft: 5}}>
                {this.state.bankInfo == null ? <span
                    style={{color: '#4876FF'}}>querying...</span> : this.state.bankInfo.bankCardNo}
              </span>
          </div>
          <div className={Styles.oneLineContent}>
            <span style={{width: '20%'}}>IFSC</span>
            :
            <span style={{width: '80%', paddingLeft: 5}}>
                {this.state.bankInfo == null ? <span
                    style={{color: '#4876FF'}}>querying...</span> : this.state.bankInfo.bankIFSCCode}
              </span>
          </div>
          <div className={Styles.oneLineContent}>
            <span style={{width: '20%'}}>User ID</span>
            :
            <span style={{width: '80%', paddingLeft: 5}}>
                {this.state.bankInfo == null ? <span
                    style={{color: '#4876FF'}}>querying...</span> : this.state.bankInfo.userCode}
              </span>
          </div>
        </Card>
      </div>

    )
  }
}

export default TradeBankInfo
